package com.dzu.easy;

/**
 * @author ZhaoDong
 * @date 2022/10/24 10:21
 * @description 392. 判断子序列
 */
public class Test392 {

    public static void main(String[] args) {
        System.out.println(isSubsequence("axc", "ahbgdc"));

    }

    // 双指针
    public static boolean isSubsequence2(String s, String t) {
        int n = s.length(), m = t.length();
        int i = 0, j = 0;
        while (i < n && j < m) {
            if (s.charAt(i) == t.charAt(j)) {
                i++;
            }
            j++;
        }
        return i == n;
    }

    // 比官方双指针快
    public static boolean isSubsequence(String s, String t) {

        for (int i = 0; i < s.length(); i++) {
            char str = s.charAt(i);

            int num = t.indexOf(str);
            if (num > -1) {
                t = t.substring(num + 1);
            } else {
                return false;
            }
        }
        return true;
    }
}
